package com.moter.demo01.requirements.re_0905.question_meituan;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws Exception {
        MoterThreadPoolExecutor executor = new MoterThreadPoolExecutor(5, new ArrayBlockingQueue<>(20));

        System.out.println();
        for (int i = 0; i < 20; i++) {
            executor.submit(User.getInstance());
        }
        executor.shutDown();
    }
}
class User implements Runnable{

    public static User getInstance(){
        return new User();
    }

    private User(){
        System.out.println("有用户下单了");
    };

    @Override
    public void run() {
        try {
            long timeout = (long) (Math.random() * 10);
            System.out.println("预计送达时间"+timeout+"s以后");
            Thread.sleep(timeout*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
